﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using TI_4_Limonade_Fabriek.Database;
using TI_4_Limonade_Fabriek.Model;
using MySql.Data;
using TI_4_Limonade_Fabriek.Properties;

namespace TI_4_Limonade_Fabriek
{
    public partial class InsertBatchScreen : Form
    {
        Batch batch;
        BatchDBController bdbc;

        public InsertBatchScreen()
        {
            InitializeComponent();
            bdbc = new BatchDBController();
        }

        private void btnSaveBatch_Click(object sender, EventArgs e)
        {
            if (tbBatchNaam.Text != "" && cbKleur.SelectedIndex != -1)
            {
                batch = new Batch
                {
                    Naam = tbBatchNaam.Text.ToString(),
                    AantalBekers = int.Parse(nudAantalBekers.Value.ToString()),
                    Mengverhouding = int.Parse(nudMengverhoudingPercentage.Value.ToString()),
                    Kleur = cbKleur.SelectedItem.ToString(),
                    Prioriteit = int.Parse(nudPrioriteit.Value.ToString()),
                    Datum = BatchDatePicker.SelectionStart.ToString("yyyy-MM-dd")
                };
                bdbc.CreateBatch(batch);
                this.Dispose();
                this.Close();
            }
            else
            {
                MessageBox.Show("Vul geldige gegevens in.");
            }
        }

        private void BatchInvoerenScherm_Load(object sender, EventArgs e)
        {
            BatchDatePicker.MaxSelectionCount = 1;
            BatchDatePicker.MinDate = DateTime.Today;
            LoadNUDs();

        }

        private void LoadNUDs()
        {
            nudMengverhoudingPercentage.Minimum = Settings.Default.MinMengverhouding;
            nudMengverhoudingPercentage.Maximum = Settings.Default.MaxMengverhouding;
            nudMengverhoudingPercentage.Increment = Settings.Default.MengverhoudingStappen;
            nudAantalBekers.Maximum = Settings.Default.AantalBekers;
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Dispose();
            this.Close();
        }

    }
}
